package HeiMa.CollectionStudy.collect;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class demo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("林青霞");
        list.add("张曼玉");
        list.add("王祖贤");
        list.add("柳岩");

//        Stream<String> stream = list.stream().filter(s -> s.length() == 3);
//
//        List<String> names = stream.collect(Collectors.toList());
//        for (String name : names){
//            System.out.println(name);
//        }

        Set<Integer> set = new HashSet<Integer>();
        set.add(10);
        set.add(20);
        set.add(30);
        set.add(40);
        set.add(50);

//        Stream<Integer> integerStream = set.stream().filter(age -> age > 25);
//        List<Integer> ages = integerStream.collect(Collectors.toList());
//        for(Integer age : ages){
//            System.out.println(age);
//        }

        String[] strArray = {"林青霞,30","张曼玉,35","王祖贤,33","柳岩,25"};
        Stream<String> stream = Stream.of(strArray).filter(s -> Integer.parseInt(s.split(",")[1]) > 28);
        Map<String, Integer> collect = stream.collect(Collectors.toMap(s -> s.split(",")[0],
                s -> Integer.parseInt(s.split(",")[1])));
        Set<String> keySet = collect.keySet();
        for(String key : keySet){
            Integer integer = collect.get(key);
            System.out.println(key + "," + integer);
        }


    }
}
